﻿@using WXY.Course.Model
@model PageViewModel<UserInfo>
@{
    var paras = this.Request.Params;
    var userInfo = ViewData["UserInfo"] as UserInfo;
}
<div class="m_rtop">
    <h3>
        <label>
            内容管理
        </label>
        <span>></span>用户管理
    </h3>
</div>
<p class="m_ptop">
    <input type="button" id="btnAdd" class="btn_bg1" value="新增用户">
</p>
@using (Html.BeginForm("UserList", "Account", FormMethod.Get, new { id = "searchForm" }))
{
    <div class="c_finfo">
        <p>
            <label>
                用户总数：
            </label>
            @Model.PageInfo.RecordCount
        </p>
        <p>
            <label>
                创建时间：
            </label>
            <input type="text" name="beginTime" id="beginTime"
                   value="@paras["beginTime"]" class="m_btn_date" />
            至
            <input type="text" name="endTime" id="endTime"
                   value="@paras["endTime"]" class="m_btn_date" />
        </p>
        <p class="m_btn">
            <input type="submit" class="m_sbtn" id="btnSearch" value="搜 索" />
        </p>
    </div>
}
<div class="m_box">
    <table width="980" cellpadding="0" cellspacing="0" border="1"
           class="tab1">
        <tr>
            <th width="150">操作</th>
            <th width="160">用户标识</th>
            <th width="160">用户名</th>
            <th width="160">真实姓名</th>
            <th width="160">创建人</th>
            <th width="140" scope="col">创建时间</th>
        </tr>
        @if (Model.HasValue)
        {
            foreach (var item in Model.Value)
            {
                <tr>
                    <td align="center">
                        <input type="hidden" class="js_code" value="@item.Code">
                        @if (item.CreateUser != null && userInfo.Code == item.CreateUser.Code)
                        {
                            <a href="javascript:void(0)" name="deleteLink">删除</a>
                        }
                    </td>
                    <td>@item.Code</td>
                    <td>@item.Name</td>
                    <td>@item.RealName</td>
                    <td>@(item.CreateUser == null ? string.Empty : item.CreateUser.RealName)</td>
                    @*<td>@Html.DisplayName(typeof(UserLevel), item.Level.ToString(), AttributeTargets.Field)</td>*@
                    <td>@item.CreateTime</td>
                </tr>
            }
        }
    </table>
</div>
<script type="text/javascript">
    $(function () {
        var normalDialog = function (msg) {
            art.dialog({
                drag: true,
                lock: true,
                width: 310,
                height: 50,
                title: '提示',
                content: msg,
                ok: function () {
                    this.close();
                }
            });
        };
        $("#btnAdd").on("click", function () {
            location.href = "@Url.Action("UserEdit","Account")";
        });

        $("a[name='deleteLink']").on("click", function () {
            var e = this;
            art.dialog({
                lock: true,
                title: '提示',
                content: '确定要删除该用户么？',
                button: [
                    {
                        value: '确定',
                        callback: function () {
                            var id = $(e).parent().find("input.js_code").val();
                            $.ajax({
                                type: 'post',
                                url: '/account/delete',
                                data: { id: id },
                                success: function (data) {
                                    if (data.IsSuccess && data.Value > 0) {
                                        art.dialog({
                                            lock: true,
                                            title: '提示',
                                            content: '删除成功',
                                            ok: function () { location.reload(); }
                                        });
                                    } else {
                                        normalDialog(data.Message);
                                    }
                                }
                            });
                        }
                    },
                    {
                        value: '取消',
                        focus: true,
                        callback: function () {
                            this.close();
                        }
                    }
                ]
            });
        });

    });
</script>
